package pers.jsan.litheopen.utils;

import java.io.Serializable;

public class Result implements Serializable {

    private int code;   //状态
    private int status;
    private Object data; //返回数据
    private String msg; //说明

    public Result() {
        super();
        this.code = CodeEnum.OTHER_ERROR.get();
        this.msg = "未知错误";
    }

    public Result(int code, Object data, String msg) {
        this.code = code;
        this.status = code;
        this.data = data;
        this.msg = code == CodeEnum.SUCCESS.get() ? "操作成功" : msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static Result ok(Object data){
        return new Result(CodeEnum.SUCCESS.get(),data,"成功");
    }
    public static Result ok(){
        return new Result(CodeEnum.SUCCESS.get(),null,"成功");
    }
    public static Result error(String msg){
        return new Result(CodeEnum.BUSINESS_ERROR.get(),null,msg);
    }
}
